<?php
/*
 * @Author: liujiachen liujiachen@neuedu.com
 * @Date: 2024-09-12 14:20:03
 * @LastEditors: liujiachen liujiachen@neuedu.com
 * @LastEditTime: 2024-09-12 14:21:14
 * @FilePath: \WWW\phpcode\phpmysql.php
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

header("Content-Type:text/html;charset=utf-8");

/* 
    链接数据库
        host        主机地址
        username    用户名
        password    密码
*/
$conn = @mysqli_connect('localhost','root','root');

//链接数据库失败
if(!$conn){
    echo '错误码：' . mysqli_connect_errno() . '<br>';
    echo '错误信息：' . mysqli_connect_error();
    exit;
}

$select = mysqli_select_db($conn,'company');

if(!$select){
    echo '选择数据库失败';
    exit;
}

// 设置编码
mysqli_set_charset($conn,'utf8');


$sql = "SELECT * FROM `pre_person`";

$res = mysqli_query($conn,$sql);

$data = [];

if($res && mysqli_num_rows($res) > 0){

  $data = mysqli_fetch_all($res,MYSQLI_ASSOC);

}
var_dump($data);

?>